package lol.clann.minecraft.springboot.bukkit.plugin.bukkit;

import lol.clann.minecraft.springboot.bukkit.plugin.logger.AbstractLogger;
import org.bukkit.Bukkit;
import org.slf4j.event.Level;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author pyz
 * @date 2019/5/5 11:09 PM
 */
public class BukkitLogger extends AbstractLogger {
    private static final Map<Level, java.util.logging.Level> mapping = new HashMap<>();

    public BukkitLogger(String name, int stackDep) {
        super(name, stackDep);
        mapping.put(Level.TRACE, java.util.logging.Level.FINE);
        mapping.put(Level.DEBUG, java.util.logging.Level.CONFIG);
        mapping.put(Level.INFO, java.util.logging.Level.INFO);
        mapping.put(Level.WARN, java.util.logging.Level.WARNING);
        mapping.put(Level.ERROR, java.util.logging.Level.SEVERE);
    }

    public BukkitLogger(String name) {
        this(name, 5);
    }

    @Override
    protected void directLog(Level level, String message, Throwable e) {
        Bukkit.getLogger().log(mapping.get(level), message, e);
    }
}
